import app from '@/app'
import { account, accountDelete, accountUpdate } from '@/api/manage/user'

import base from '@/app/model'

// 继承总模型
const model = new base;

model.get = () => {
  return new Promise((resolve, jeject) => {
    app.ui.loading()
    account().then(res => {
      model.setList(res)
      resolve(res)
    }).catch(res => {
      jeject(res)
    }).finally(() => {
      app.ui.loadingClose()
    })
  })
}

model.update = (...arge) => {
  return new Promise((resolve, jeject) => {
    accountUpdate(...arge).then(res => {
      model.get()
      app.ui.message('success', res.message)
      resolve(res)
    }).catch(res => {
      app.ui.message('error', 'error.' + res.message)
      jeject(res)
    })
  })
}

model.del = (...arge) => {
  return new Promise((resolve, jeject) => {
    accountDelete(...arge).then(res => {
      model.get()
      app.ui.message('success', res.message)
      resolve(res)
    }).catch(res => {
      app.ui.message('error', 'error.' + res.message)
      jeject(res)
    })
  })
}

export default model